home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / _archvrs / unix / arc521.lha / arc / arcmatch.c < prev    next >
C/C++ Source or Header  |  1989-08-08  |  3KB  |  137 lines

  1. /*
  2.  * $Header: arcmatch.c,v 1.6 88/07/31 18:50:18 hyc Exp $
  3.  */
  4.  
  5. /*
  6.  * ARC - Archive utility - ARCMATCH
  7.  * 
  8.  * Version 2.17, created on 12/17/85 at 20:32:18
  9.  * 
  10.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  11.  * 
  12.  * By:  Thom Henderson
  13.  * 
  14.  * Description: This file contains service routines needed to maintain an
  15.  * archive.
  16.  * 
  17.  * Language: Computer Innovations Optimizing C86
  18.  */
  19. #include <stdio.h>
  20. #include "arc.h"
  21.  
  22. int    strcmp(), strlen();
  23. void    abort();
  24. char    *strcpy();
  25.  
  26. int
  27. match(n, t)            /* test name against template */
  28.     char           *n;    /* name to test */
  29.     char           *t;    /* template to test against */
  30. {
  31. #if    MTS
  32.     fortran         patbuild(), patmatch(), patfree();
  33.     static int      patlen = (-1);
  34.     static int      patwork = 0;
  35.     static int      patswch = 0;
  36.     char            patccid[4];
  37.     static char     patchar[2] = "?";
  38.     static char     oldtemp[16] = 0;
  39.     int             namlen, RETCODE;
  40.  
  41.     if (strcmp(t, oldtemp)) {
  42.         if (patwork)
  43.             patfree(&patwork);
  44.         strcpy(oldtemp, t);
  45.         patlen = strlen(oldtemp);
  46.         patbuild(oldtemp, &patlen, &patwork, &patswch, patccid, patchar, _retcode RETCODE);
  47.         if (RETCODE > 8) {
  48.             printf("MTS: patbuild returned %d\n", RETCODE);
  49.             abort("bad wildcard in filename");
  50.         }
  51.     }
  52.     namlen = strlen(n);
  53.     patmatch(n, &namlen, &patwork, _retcode RETCODE);
  54.     switch (RETCODE) {
  55.     case 0:
  56.         return (1);
  57.     case 4:
  58.         return (0);
  59.     default:
  60.         abort("wildcard pattern match failed");
  61.     }
  62. }
  63.  
  64. #else
  65. #if    !UNIX
  66.     upper(n);
  67.     upper(t);        /* avoid case problems */
  68. #endif    /* UNIX */
  69. #if    GEMDOS
  70.     char *strstr(), *i;    /* allow "*.*" to mean '*' */
  71.     if (i=strstr(t,"*.*")) {
  72.         i++;
  73.         *i='\0';
  74.     }
  75.     return(pnmatch(n, t, 0));
  76. #else
  77.     /* first match name part */
  78.  
  79.     while ((*n && *n != '.') || (*t && *t != '.')) {
  80.         if (*n != *t && *t != '?') {    /* match fail? */
  81.             if (*t != '*')    /* wildcard fail? */
  82.                 return 0;    /* then no match */
  83.             else {    /* else jump over wildcard */
  84.                 while (*n && *n != '.')
  85.                     n++;
  86.                 while (*t && *t != '.')
  87.                     t++;
  88.                 break;    /* name part matches wildcard */
  89.             }
  90.         } else {    /* match good for this char */
  91.             n++;    /* advance to next char */
  92.             t++;
  93.         }
  94.     }
  95.  
  96.     if (*n && *n == '.')
  97.         n++;        /* skip extension delimiters */
  98.     if (*t && *t == '.')
  99.         t++;
  100.  
  101.     /* now match name part */
  102.  
  103.     while (*n || *t) {
  104.         if (*n != *t && *t != '?') {    /* match fail? */
  105.             if (*t != '*')    /* wildcard fail? */
  106.                 return 0;    /* then no match */
  107.             else
  108.                 return 1;    /* else good enough */
  109.         } else {    /* match good for this char */
  110.             n++;    /* advance to next char */
  111.             t++;
  112.         }
  113.     }
  114.  
  115.     return 1;        /* match worked */
  116. #endif    /* GEMDOS */
  117. }
  118. #endif
  119.  
  120. void
  121. rempath(nargs, arg)        /* remove paths from filenames */
  122.     int             nargs;    /* number of names */
  123.     char           *arg[];    /* pointers to names */
  124. {
  125.     char           *i, *rindex();    /* string index, reverse indexer */
  126.     int             n;    /* index */
  127.  
  128.     for (n = 0; n < nargs; n++) {    /* for each supplied name */
  129.         if (!(i = rindex(arg[n], '\\')))    /* search for end of
  130.                              * path */
  131.             if (!(i = rindex(arg[n], '/')))
  132.                 i = rindex(arg[n], ':');
  133.         if (i)        /* if path was found */
  134.             arg[n] = i + 1;    /* then skip it */
  135.     }
  136. }
  137.